// pages/userStatistics/UserEdit/UserEdit.js
const controllers = require('../../controllers/controllerIndex.js').controller;
const app = getApp();
Page({
  data: {
    nick:null,
    mobile:null,
    callback:null//回调方法名称
  },
  onLoad: function (options) {
    this.callback = options.callback || "";
    let mobile = options.mobile;
    if(mobile){
      this.setData({
        mobile:mobile
      });
    }

  },
  onSubmit: function () {
    let that =this;
    let d=this.data;
    let ps = {
      nick:d.nick,
      mobile:d.mobile,
      sessionId: wx.getStorageSync('token'),
      shopId:wx.getStorageSync('shopId'),
    };
    return controllers.createAccount(ps).then((res)=>{
      let data = res.data;
      wx.showToast({
        title: "保存成功",
        icon: 'none',
      });

      if(that.callback){//回调数据
        let pages = getCurrentPages();
        let parent = pages[pages.length - 2];  //上一个页面
        if (parent) {//非父页面调用，不处理
          let fn = parent[that.callback];
          fn&&fn.call(that, data);
        }
      }
      wx.navigateBack(1);//返回

    });
  },

  inputBox: function (e) {
    var db = e.currentTarget.dataset;
    let data = {};
    data[db.name] = e.detail.value;
    this.setData(data);
  }, 

})